package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark70Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark70 extends BaseMark {

    LayoutWatermark70Binding binding;

    public Mark70(@NonNull Context context) {
        super(context);
    }

    public Mark70(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark70(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark70Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.bottom);
            for (int i = 3; i < binding.mid.getChildCount(); i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark70Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "title70", binding.binding1);
        setText(binding.binding2, "subTitle70", binding.binding2);

        setText(binding.binding4, "phone70", binding.binding3);
        setText(binding.binding6, "time70", binding.binding5);
        setTime(binding.binding6, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

        setText(binding.binding8, "didian70", binding.binding7);
        setText(binding.binding10, "jingdu70", binding.binding9);

        setText(binding.binding12, "jingwei70", binding.binding11);
        String[] s = new EditItem("jingwei70").getStringPoints();
        binding.binding12.setText(s[1]);
        binding.binding14.setText(s[0]);

        setText(binding.binding16, "angle70", binding.binding15);
        setText(binding.binding18, "height70", binding.binding17);
        setText(binding.binding20, "weather70", binding.binding19);
        setText(binding.binding22, "beizhu70", binding.binding21);

        setText(binding.binding24, "build70", binding.binding23);
        setText(binding.binding26, "check70", binding.binding25);
        setText(binding.binding28, "work70", binding.binding27);
        setText(binding.binding30, "design70", binding.binding29);
        setText(binding.binding32, "watch70", binding.binding31);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title70", "标题"));
        list.add(new EditItem("subTitle70", "副标题"));
        list.add(new EditItem("phone70", "手机号"));
        list.add(new EditItem("time70", "时间", true));
        list.add(new EditItem("didian70", "地点"));
        list.add(new EditItem("jingdu70", "定位精度"));
        list.add(new EditItem("jingwei70", "经纬度"));
        list.add(new EditItem("angle70", "方位角"));
        list.add(new EditItem("height70", "海拔"));
        list.add(new EditItem("weather70", "天气"));
        list.add(new EditItem("beizhu70", "备注"));

        list.add(new EditItem("build70", "建设单位"));
        list.add(new EditItem("check70", "监理单位"));
        list.add(new EditItem("work70", "施工单位"));
        list.add(new EditItem("design70", "设计单位"));
        list.add(new EditItem("watch70", "勘察单位"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding6, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        } else {
            super.onValueChange(item);
        }
    }
}
